Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
How can I checkor solve for "undefined" in JavaScript?

What is the most appropriate way to test if a variable is undefined in JavaScript?

I have a block of Published Yes and No.

<div class="card mb-3">
    <div class="card-header">{{ __('Published') }}</div>
    <div class="card-body">
        <div class="form-check">
            <input class="form-check-input published_filter" type="radio" name="published" id="yes" value="1">
            <label class="form-check-label" for="yes">
                Yes
            </label>
        </div>
        <div class="form-check">
            <input class="form-check-input published_filter" type="radio" name="published" id="no" value="0">
            <label class="form-check-label" for="no">
                No
            </label>
        </div>
    </div>
</div>

When I click Yes and No, I see this alert undefined.

<script>
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(".published_filter").change(function(){

        var publish = $(this).val();
        $.ajax({
            type:'POST',
            url:"{{ route('category-filter') }}",
            data:{publish: publish},
            success:function(data){
                alert(data.success);
            }
        });
    });
</script>JAVA
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!